local require = require
local uu     = require("modules.commhm.utils")
local config = require("modules.business_common.business_config")
local http   = require("modules.business_common.utils.business_http")
local auth_md5  = require("modules.business_common.auth.md5")
local log = require("modules.commhm.log")

local ngx = ngx
local curr = os.time

local table = table
local pairs = pairs
local ipairs = ipairs
local tonumber = tonumber
local tostring = tostring
local loadstring = table.loadstring

local FOO = {
    _VERSION = '0.0.1',
}

local http_request = function( uin, request )
    if not (request and request.act) then
        return nil
    end

    request.uin = uin
    request.time = uu.now()
    request.encrypt_ver = auth_md5.ENCRYPT.MD5_VER2
    request.md5 = auth_md5.make_md5_v2(request)

    local server = config.get_welfare_server_url()
    local response = loadstring(http.Get(server, request) or 'nil')
    if response and tonumber(response.ret) == 0 then
        return true, response.data or {}
    end

    -- 失败日志
    http.Log(uu.to_str({ server = server, request = request, response = response }))
    return false
end

-- !@ 付费开通会员通知福利服
FOO.payvip_active_sync  = function( uin, month )
    uin = uin or ngx.ctx.m_params.uin
    return http_request(uin, {
        act = 'payvip_active_sync',
        month = month,
    })

end

return FOO